import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;


class SingleTest{

    private  volatile  static  SingleTest instance =null;
    private static int a;

    public SingleTest getSingleTest(){
        if(instance==null) {
            synchronized (SingleTest.class) {
                if (instance == null) {
                    instance = new SingleTest();
                }
            }
        }
        return instance;
    }


}
class MyBlockQueue{

    private int[] arr = new int[10];

    private  int head=0;
    private  int end =0;
    private  int usedSize;
    public int  take() throws InterruptedException {
        if(usedSize<=0){
            synchronized (arr) {
                arr.wait();
            }
        }
        int tmp = arr[head];
        head = (head+1)%arr.length;
        usedSize--;
        arr.notify();
        return tmp;
    }

    public void put(int x) throws InterruptedException {

        if(usedSize>=arr.length){
            synchronized (arr){
                arr.wait();
            }
        }

        arr[end] = x;
        end = (end+1)%arr.length;
        usedSize++;
        arr.notify();

    }

}
class MyThreadPool{

    public MyThreadPool(int n){

        for(int i = 0;i<n;i++){
            Thread thread = new Thread(){
                @Override
                public void run() {
                     try {
                       Runnable runnable = blockingDeque.take();
                         runnable.run();
                    } catch (InterruptedException e) {
                        System.out.println("抛出异常了");
                        throw new RuntimeException(e);
                    }

                }
            };
            thread.start();
        }
    }

    public static BlockingDeque<Runnable> blockingDeque = new LinkedBlockingDeque<>();
    public void submit(Runnable runnable){

        blockingDeque.offer(runnable);
    }
}

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        ExecutorService executorService1 = Executors.newCachedThreadPool();
        System.out.println(Integer.MAX_VALUE);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for(int i =0;i<10;i++){
                    System.out.println(i);
                }
            }
        };
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("111");
                return 11;
            }
        };
        executorService.execute(runnable);
        FutureTask futureTask = (FutureTask) executorService.submit(callable);
        System.out.println( futureTask.get());

    }
    public static void main2(String[] args) {

        MyThreadPool myThreadPool = new MyThreadPool(10);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for(int i =0;i<10;i++){
                    System.out.println(i);
                }
            }
        };

        myThreadPool.submit(runnable);
    }
    public static void main1(String[] args) throws Exception {

        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return 10;
            }
        };
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
           Thread thread1 = new Thread(futureTask);
           thread1.start();

         System.out.println(futureTask.get());

         BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>();

        /* ExecutorService executorService = Executors.newFixedThreadPool(10);

         executorService.submit(new Runnable() {
             @Override
             public void run() {
                 for(int i = 0;i<1000;i++){
                     System.out.println("1111");
                 }
             }
         });

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("111");
            }
        },1000);*/

    }
}
